<template>
  <div class="page">
    <!-- tab1 -->
		<app-tab1></app-tab1>
    <!-- tab2 -->
    <van-tabs v-model="tab2" class="tab2" @click="tabClick">
      <van-tab title="全部"></van-tab>
      <van-tab v-for="item in class_fl" :title="item.title" :data-id="item.id"></van-tab>
    </van-tabs>
    <div class="list_box">
      <van-list v-model="loading" :finished="finished" @load="getList">
        <router-link v-for="(item,index) in list" :key="index" :to="'/list0_1?id='+item.id+'&t='+item.title" class="list_item">
            <div class="titBox">
              <div class="tit">{{item.title}}</div><span class="listLabel listLabel_1">课件数：{{item.count}}</span>
            </div>
            <p>{{item.created_at}}</p>
        </router-link>
        <div class="finished" v-if="finished">加载完毕</div>
      </van-list>
    </div>
  </div>
</template>

<script>
import { Dialog } from "vant";
import tab1 from '@/components/common/tab1';
export default {
  data() {
    return {
      tab2:0,
      class_fl:[],
      list: [],
      loading: false,
      finished: false
    };
  },
  mounted: function() {
    this.setCookie('scrollTop',0)
    this.getClass(); 
    maxusJSB.tojson({title:"培训中心"})
  },
		components:{
			"app-tab1":tab1
		},
  methods: {
    // 请求列表
    getList(typeid) {
      if(typeid==undefined){
        typeid="-1"
      }
      this.$http
        .get("?key=&request=front&operation=course&client=1&by=admin&typeid="+typeid+"&user_id="+this.getUserID+"&_="+Date.parse(new Date()))
        .then(response => {
          if(response.ret==1){
            this.list=response.data
            this.loading=false
            this.finished=true
          }
        });
    },
    // 请求分类
    getClass() {
      this.$http
        .get("?key=&request=front&operation=course-category&client=1&by=admin&_="+Date.parse(new Date()))
        .then(response => {
          if(response.ret==1){
            this.class_fl=response.data
          }
        });
    },
    // 切换TAB
    tabClick(index, title){
      var index=index-1
      console.log(index);
      
     
      if(index==-1){
        var tt="-1"
      }else{
        var tt=this.class_fl[index].id
      }
      this.getList(tt)    
    }
  }
};
//统计
(function(g, d, s, t) {
		g['_cts'] = g['_cts'] || {};
		g['_cts'][t] = g['_cts'][t] || {};
		g[t] = g[t] || function() {
			(g[t].c = g[t].c || []).push(arguments);
		}
		var c = d.createElement(s),
			h = d.getElementsByTagName(s)[0];
		c.src = '//c.saicmaxus.com/dmp/t.js';
		h.parentNode.insertBefore(c, h);
	})(window, document, 'script', 'pilot');

	pilot('set', 'siteId', 'CCS82280');
	pilot('set', 'accountId', 'pilot');
	pilot('set', 'baseUrl', 'https://trk.maxuscloud.com/');
	pilot('track', 'pageview','index0');
</script>